# -*- coding: utf-8 -*-

# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: https://doc.scrapy.org/en/latest/topics/item-pipeline.html
import mysql.connector


class FenghuangPipeline(object):

	def process_item(self, item, spider):
		insert_data_into_mysql((item['title'], item['news_url'], item['time']))


def insert_data_into_mysql(data):
	conn = mysql.connector.connect(host='127.0.0.1', port='3306', database='spider', user='root', password='123',
								   use_unicode=True)
	c = conn.cursor()
	c.execute('INSERT INTO fenghuang_new (`title`, `url`, `time`) VALUES (%s, %s, %s)', data)
	conn.commit()
	c.close()
	conn.close()
